back to Index
2014-07-20
some code writen by vincent to test topgear
In [3]:
# Cross-notebook include shim
with open("nbinclude.ipynb") as nbinclude_f: # don't rename nbinclude_f
import IPython.nbformat.current
get_ipython().run_cell(IPython.nbformat.current.read(nbinclude_f, 'json').worksheets[0].cells[0].input)
In [4]:
nbinclude("robot")
In [5]:
r = Robot()
In [9]:
r.cmd?
In [10]:
r.cmd(self, 1, 1);
In [6]:
r.enable()
In [8]:
r.cmd(1,1)
In [9]:
r.cmd(0,0)
In [10]:
while True:
for i in range(0,100):
r.cmd(i*0.01, i*0.01)
for i in range(0,100):
r.cmd(1-i*0.01, 1-i*0.01)
In [11]:
r.cmd(0,0)
In [12]:
import time
In [13]:
for i in range(0, 10):
time.sleep(1)
print(i)
In [14]:
while True:
for i in range(0,100):
r.cmd(i*0.01, i*0.01)
time.sleep(.5)
for i in range(0,100):
r.cmd(1-i*0.01, 1-i*0.01)
time.sleep(.5)
In [15]:
r.cmd(0,0
)
In [16]:
while True:
r.cmd(.5,.5)
time.sleep(.5)
r.cmd(-.5,-.5)
time.sleep(.5)
In [17]:
r.cmd(0,0
)
In [ ]:
r.cmd(0,0)
In [18]:
from IPython.html.widgets import interact, interactive, fixed
from IPython.html import widgets
from IPython.display import clear_output, display, HTML
In [19]:
def show_args(**kwargs):
s = '<h3>Arguments:</h3><table>\n'
for k,v in kwargs.items():
s += '<tr><td>{0}</td><td>{1}</td></tr>\n'.format(k,v)
s += '</table>'
display(HTML(s))
In [20]:
i = interact(show_args,
right=(-1.,1.,0.1),
left=(-1.,1.,0.1));
In [38]:
right
In [21]:
def print_two(one, two):
print(one)
print(two)
In [22]:
print_two(1,2)
In [23]:
i = interact(print_two,
one=(-1.,1.,0.1),
two=(-1.,1.,0.1));
In [24]:
i = interact(r.cmd,
l=(-1.,1.,0.1),
r=(-1.,1.,0.1));
In [25]:
r.cmd(1,1)
In [26]:
r.cmd(0,0)
In [27]:
def drive_robot(left, right):
r.cmd(left, right)
In [28]:
i = interact(drive_robot,
left=(-1.,1.,0.1),
right=(-1.,1.,0.1));
In [29]:
r.cmd(-.35,-.7)
time.sleep(1)
r.cmd(0,0)
In [30]:
r.cmd(.35,.7)
time.sleep(1)
r.cmd(0,0)
In [31]:
def spin(seconds):
r.cmd(.35,-.7)
time.sleep(seconds)
r.cmd(0,0)
In [33]:
spin(.2)
In [34]:
def square():
for i in range(0,4):
r.cmd(.35,.7)
time.sleep(.5)
r.cmd(0,0)
spin(.2)
In [36]:
square()
In [97]:
r.cmd(0, 0)
In [ ]: